//反转链表
#include<stdio.h>
#include<stdlib.h>
struct ListNode
{
	int val;
	struct ListNode* next;
};
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k) {
	// write code here
	struct ListNode* slow = pListHead;
	struct ListNode* fast = pListHead;
	int ret = 1;
	while (fast && fast->next)
	{
		if (1==ret)
		{
			int i = 0;
			for (i = 0; i < k; i++)
			{
				fast = fast->next;
				ret++;
			}
		}
		slow = slow->next;
		fast = fast->next;
	}
	slow->next->next = NULL;
	return slow->next;
}
void SLTNodePrintf(struct ListNode* ps)
{
	struct ListNode* cur = ps;
	while (cur)
	{
		printf("%d->", cur->val);
		cur = cur->next;
	}
	printf("NULL\n");
}

int main()
{
	struct ListNode* n1 = malloc(sizeof(struct ListNode));
	struct ListNode* n2 = malloc(sizeof(struct ListNode));
	struct ListNode* n3 = malloc(sizeof(struct ListNode));
	struct ListNode* n4 = malloc(sizeof(struct ListNode));

	n1->val = 1;
	n2->val = 2;
	n3->val = 6;
	n4->val = 3;

	n1->next = n2;
	n2->next = n3;
	n3->next = n4;
	n4->next = NULL;
	SLTNodePrintf(n1);

	struct ListNode* newnode = FindKthToTail(n1, 3);
	SLTNodePrintf(newnode);

	return 0;
}